using EasyXaf.EntityDesigner.Editors.CodeEditors;
using Microsoft.AspNetCore.Components;

namespace EasyXaf.EntityDesigner.Editors.DetailViewEditors.Components;

public partial class LayoutSourceCodeComponent
{
    private CodeEditorModel CodeModel { get; set; }

    [Parameter]
    public string CssClass { get; set; }

    [Parameter]
    public string SourceCode { get; set; }

    [Parameter]
    public EventCallback<string> SourceCodeChanged { get; set; }

    protected override void OnInitialized()
    {
        base.OnInitialized();

        CodeModel = new CodeEditorModel
        {
            Language = "xml",
            Code = SourceCode
        };

        CodeModel.CodeChanged += async (sender, code) =>
        {
            await SourceCodeChanged.InvokeAsync(code);
        };
    }
}